package cn.finedo.highway.controller;

import cn.finedo.common.domain.ReturnValueDomain;
import cn.finedo.common.non.NonUtil;
import cn.finedo.fsdp.service.common.jdbc.JdbcTemplate;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description:手动统计数据
 * @author: lizheng
 * @createDate: 2023-2-20
 * @version: 1.0
 */
@RestController
public class StatisticsController {

    @Resource(name = "fsdpJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Resource(name = "wayJdbcTemplate")
    private JdbcTemplate wayJdbcTemplate;

    /**
     * @param requestbody Json格式
     * {
     *     "startTime":"2022-01-01",
     *     "endTime":"2022-01-02"
     * }
     * @return
     */
    @RequestMapping(value = "/statisticsByDate")
    public ReturnValueDomain<Object> statistics(@RequestBody String requestbody){
        ReturnValueDomain<Object> ret = new ReturnValueDomain<>();
        JSONObject jsonobj= NonUtil.isNon(requestbody) ? new JSONObject() : JSON.parseObject(requestbody);
        String startTime = jsonobj.getString("startTime");
        String endTime = jsonobj.getString("endTime");
        if(NonUtil.isNon(startTime)){
            return ret.setFail("startTime为空");
        }
        if(NonUtil.isNon(endTime)){
            return ret.setFail("endTime为空");
        }
//        jdbcTemplate
        return ret.setSuccess("统计成功");
    }
}
